import QtQuick
import QtQuick.Layouts
import QtCharts

Rectangle {
    Layout.fillWidth: true
    Layout.fillHeight: true

    ChartView {
        id: chartView
        title: "图例"
        titleFont.bold: true
        titleFont.pointSize: 14
        anchors.fill: parent
        antialiasing: true

        // 1. 设置图例可见
        legend.visible: true

        // 2. 设置图例边框和背景样式
        legend.backgroundVisible: true
        legend.color: "#E0E0E0"
        legend.borderColor:  "#999999"

        // 3. 设置图例字体
        legend.font.family: "Courier"
        legend.font.pointSize: 12
        legend.font.bold: true

        // 4. 设置标签颜色
        legend.labelColor: "#1296FF"

        // 5. 设置标记形状
        legend.markerShape: Legend.MarkerShapeFromSeries

        // 6. 反转标识
        legend.reverseMarkers: true

        // 7. 设置图例位置
        legend.alignment: Qt.AlignTop

        // QML 不支持
        // legend.showToolTips: true

        ValueAxis {
            id: valueAxisX
            min: 0
            max: 4
            titleText: "X Title"
        }

        ValueAxis {
            id: valueAxisY
            min: 0
            max: 16
            titleText: "Y Title"
        }

        LineSeries {
            name: "line1"
            XYPoint { x: 0; y: 0 }
            XYPoint { x: 1; y: 1 }
            XYPoint { x: 2; y: 4 }
            XYPoint { x: 3; y: 9 }
            XYPoint { x: 4; y: 16 }
            axisX: valueAxisX
            axisY: valueAxisY
        }

        LineSeries {
            name: "line2"
            XYPoint { x: 0; y: 2 }
            XYPoint { x: 1; y: 4 }
            XYPoint { x: 2; y: 5 }
            XYPoint { x: 3; y: 8 }
            XYPoint { x: 4; y: 12 }
            axisX: valueAxisX
            axisY: valueAxisY
        }
    }
}
